package com.huirui.server.controller.admin;

import com.huirui.server.pojo.dto.StockShortageRecordDto;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.StockShortageRecordVo;
import com.huirui.server.service.StockShortageRecordService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController("adminStockShortageRecordController")
@RequestMapping("/admin/stock/shortage/record")
@Slf4j
@Validated
@Tag(name = "缺货商品处理", description = "缺货申请处理")
@RequiredArgsConstructor
public class StockShortageRecordController {

    private final StockShortageRecordService stockShortageRecordService;

    @GetMapping
    public Result<PageResult<StockShortageRecordVo>> listStockShortageApplication(
            @RequestParam(required = false) String productName,
            @RequestParam(required = false) String brandName,
            @RequestParam(required = false) Integer status,
            @RequestParam Long page,
            @RequestParam Long pageSize
    ) {
        PageResult<StockShortageRecordVo> res = stockShortageRecordService.listStockShortageApplication(productName, brandName, status, page, pageSize);
        return Result.success(res);
    }


    @DeleteMapping
    public Result<Void> handleDeleteApplication(@RequestParam Long id) {
        stockShortageRecordService.handleDeleteApplication(id);
        return Result.success();
    }

    @PutMapping
    public Result<Void> updateStockShortageRecord(@RequestBody StockShortageRecordDto stockShortageRecordDto) {
        stockShortageRecordService.updateStockShortageRecord(stockShortageRecordDto);
        return Result.success();
    }


}
